package net.lastcoder.ifserver.terminate;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolDecoderOutput;

/**
 * auth: WenYF
 * date: 2016/11/23
 */
public class TerminateDecoder extends CumulativeProtocolDecoder {
    @Override
    protected boolean doDecode(IoSession ioSession, IoBuffer ioBuffer
            , ProtocolDecoderOutput out) throws Exception {

        if (ioBuffer.hasRemaining()) {
            byte[] data = new byte[ioBuffer.remaining()];
            ioBuffer.get(data);

            String str = new String(data);

            out.write(str);
            return true;
        } else {
            return false;
        }

    }
}
